<?php
// 获得历史预约信息
// header("content-type:text/html;charset=UTF-8");
include_once("conn.php");
include_once("d_getLoginInfo.php");

if ((!isset($_GET['bDate']) && !isset($_GET['eDate'])) || !isset($_GET['send'])) {
    $select_infos =
        "SELECT * FROM cases_infos LEFT JOIN user_infos ON cases_infos.cases_userID = user_infos.user_ID
     WHERE cases_infos.cases_docID = '" . $doc_ID . "'
     ORDER BY cases_infos.cases_date DESC ";

}

if (isset($_GET['bDate']) || isset($_GET['eDate'])) {
    $b_date = $_GET['bDate'];
    $e_date = $_GET['eDate'];
    if ($b_date == "") {
        $b_date = "1970-01-01";
    }

    if ($e_date == "") {
        date_default_timezone_set('Asia/Shanghai');
        $e_date = date("Y-m-d");
    }

    $select_infos =
        "SELECT * FROM cases_infos,user_infos
     WHERE cases_infos.cases_date BETWEEN '" . $b_date . "' AND '" . $e_date . "'
     AND cases_infos.cases_docID = '" . $doc_ID . "'
     ORDER BY cases_infos.cases_date DESC ";
}

if (isset($_GET['sendcasesID'])) {
    $casesID = $_GET['sendcasesID'];
    $select_infos =
        "SELECT * FROM cases_infos LEFT JOIN user_infos ON cases_infos.cases_userID = user_infos.user_ID
     WHERE cases_infos.cases_ID LIKE '%" . $casesID . "%'
     AND cases_infos.cases_docID = '" . $doc_ID . "'
     ORDER BY cases_infos.cases_date DESC ";
}

if (isset($_GET['senduserID'])) {
    $userID = $_GET['senduserID'];
    $select_infos =
        "SELECT * FROM cases_infos LEFT JOIN user_infos ON cases_infos.cases_userID = user_infos.user_ID
     WHERE cases_infos.cases_userID LIKE '%" . $userID . "%'
     AND cases_infos.cases_docID = '" . $doc_ID . "'
     ORDER BY cases_infos.cases_date DESC ";
}

if (isset($_GET['sendpetID'])) {
    $petID = $_GET['sendpetID'];
    $select_infos =
        "SELECT * FROM cases_infos LEFT JOIN user_infos ON cases_infos.cases_userID = user_infos.user_ID
     WHERE cases_infos.cases_petID LIKE '%" . $petID . "%'
     AND cases_infos.cases_docID = '" . $doc_ID . "'
     ORDER BY cases_infos.cases_date DESC ";
}

if ($result_infos = mysqli_query($connect_DB, $select_infos)) {
    if (mysqli_num_rows($result_infos) > 0) {
        while ($row_infos = mysqli_fetch_object($result_infos)) {
            echo "
            <div class='info-notnull-div'>
                <div class='info-cases'>" . $row_infos->cases_ID . "</div>
                <div class='info-userID'>" . $row_infos->cases_userID . "</div>
                <div class='info-userName'>" . $row_infos->user_Name . "</div>
                <div class='info-petID'>" . $row_infos->cases_petID . "</div>
                <div class='info-petName'>" . $row_infos->cases_petName . "</div>
                <div class='info-petType'>" . $row_infos->cases_petType . "</div>
                <div class='info-overDate'>" . $row_infos->cases_date . "</div>
                <div class='info-do'><a href='doc_CasesTable.php?casesID=" . $row_infos->cases_ID . "'>查看详情</a></div>
            </div> ";
        }
    } else {
        echo "
        <div class='info-null-div'>
            暂 无 信 息
        </div> ";
    }
} else {
    echo "
        <div class='info-null-div'>
            查询失败：" . $select_infos . "
        </div> ";
}
// echo $select_infos;

$connect_DB->close();
?>